#!/bin/bash

# Load gparted live functions
. /usr/share/gparted/bin/gl-functions

# If no boot parameter gp_prerun, return.
# //NOTE// Do not use "exit 1", use "return 1" here since all these script here is run as function like this:
# for script in /etc/gparted-live/gparted-live.d/S[0-9][0-9]*; do
#  . $script
# done
# So if it's "exit 1", the scripts (e.g. S09start-X) after this script "S08pre-run" will not be run.
if ! grep -q -Ew gp_prerun /proc/cmdline; then
  exit
fi
parse_cmdline_option "gp_prerun"

if [ -n "$gp_prerun" ]; then
  # Run it
  echo "**************************"
  # Run it
  echo "Now run \"$gp_prerun\": $gp_prerun..."
  # Since "$gp_prerun" might not be exe mode, so we test it if it's script, use . $gp_prerun, else, run it directly.
  if [ "$(LANG=C file -Ls "$gp_prerun" 2>/dev/null | grep -iE "shell script")" ]; then
    $gp_prerun
  else
    eval $gp_prerun
  fi
fi
